/*
  In App.xaml:
  <Application.Resources>
      <vm:ViewModelLocatorTemplate xmlns:vm="clr-namespace:ExcelMergeDocs.WinClient"
                                   x:Key="Locator" />
  </Application.Resources>
  
  In the View:
  DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"

  You can also use Blend to do all this with the tool's support.
  See http://www.galasoft.ch/mvvm
*/

using GalaSoft.MvvmLight;
using ExcelMergeDocs.WinClient.Services;

namespace ExcelMergeDocs.WinClient.ViewModel {
    /// <summary>
    /// This class contains static references to all the view models in the
    /// application and provides an entry point for the bindings.
    /// </summary>
    public class ViewModelLocator {
        private static MainViewModel _main;

        /// <summary>
        /// Initializes a new instance of the ViewModelLocator class.
        /// </summary>
        public ViewModelLocator() {
            _main = new MainViewModel(new DocSelectionService());

            if (ViewModelBase.IsInDesignModeStatic) {
                // Create design time services and viewmodels
                var ws1 = new WSViewModel {
                    IsSelected = true,
                    Name = "worksheet1"
                };
                var ws2 = new WSViewModel {
                    IsSelected = true,
                    Name = "worksheet2"
                };
                var ws3 = new WSViewModel {
                    IsSelected = false,
                    Name = "worksheet3"
                };

                var doc1 = new DocViewModel {
                    Name = "something.xlsx",
                    IsSelected = true,
                    IsExpanded = true
                };
                doc1.Worksheets.Add(ws1);
                doc1.Worksheets.Add(ws2);
                doc1.Worksheets.Add(ws3);

                var doc2 = new DocViewModel {
                    Name = "something2.xlsx",
                    IsSelected = false
                };
                doc2.Worksheets.Add(ws1);
                doc2.Worksheets.Add(ws2);
                doc2.Worksheets.Add(ws3);

                var doc3 = new DocViewModel {
                    Name = "something.xlsx",
                    IsSelected = true
                };
                doc3.Worksheets.Add(ws1);
                doc3.Worksheets.Add(ws2);
                doc3.Worksheets.Add(ws3);

                _main.Documents.Add(doc1);
                _main.Documents.Add(doc2);
                _main.Documents.Add(doc3);
            } else {
                 //Create run time services and view models
            }

        }

        /// <summary>
        /// Gets the Main property which defines the main viewmodel.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public MainViewModel Main {
            get {
                return _main;
            }
        }
    }
}